import 'package:flutter/material.dart';
import 'package:qgchat/bloc/blocProvider.dart';
import 'package:qgchat/bloc/my/blacklistBloc.dart';
import 'package:qgchat/common/global/global.dart';
import 'package:qgchat/http/models/blackListModel.dart';
import 'package:qgchat/widgets/appbarCustom.dart';
import 'package:qgchat/widgets/avatar.dart';
import 'package:qgchat/widgets/line.dart';

///
/// 黑名单页面
/// page黑名单
///

class Blacklist extends StatelessWidget {
  const Blacklist({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: appBar(),
      body: Container(
        width: w100(context),
        height: h100(context),
        padding: EdgeInsets.symmetric(horizontal: px(30)),
        color: Colors.white,
        child: SingleChildScrollView(
          physics: BouncingScrollPhysics(),
          child: SafeArea(
            bottom: true,
            child: blacklistList(context),
          ),
        ),
      ),
    );
  }

  // 移出按钮
  void _shiftOutClick(context, id) {
    BlackListBloc bloc = BlocProvider.of<BlackListBloc>(context);
    bloc.outBlack(id);
  }

  /// appbar
  Widget appBar() {
    return AppbarCustom('黑名单');
  }

  /// 黑名单列表
  Widget blacklistList(context) {
    BlackListBloc bloc = BlocProvider.of<BlackListBloc>(context);
    return StreamBuilder(
      stream: bloc.blackStream,
      builder: (BuildContext context, AsyncSnapshot snapshot) {
        return Container(
          child: Column(
            children: bloc.blacklist.map((item) {
              return _blacklistListItemBuilder(context, item);
            }).toList(),
          ),
        );
      },
    );
  }

  /// 黑名单列表单项构造器
  Widget _blacklistListItemBuilder(context, BlackListModel item) {
    return Container(
        child: Column(
      children: <Widget>[
        Container(
          height: px(168),
          child: Row(
            children: <Widget>[
              /// 头像
              Container(
                margin: EdgeInsets.only(right: px(20)),
                child: Avatar(
                  '${item.memberHead}',
                  true,
                ),
              ),

              /// 用户信息
              Container(
                width: px(363),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    /// 用户名与ID
                    Container(
                      margin: EdgeInsets.only(bottom: px(10)),
                      child: Text.rich(
                        TextSpan(children: [
                          TextSpan(
                            text: '${item.memberNickname}  ',
                            style: TextStyle(
                              fontSize: px(28),
                              color: col('303133'),
                            ),
                          ),
                          TextSpan(
                            text: 'ID:${item.id}',
                            style: TextStyle(
                              fontSize: px(24),
                              color: col('bfc2cc'),
                            ),
                          )
                        ]),
                      ),
                    ),

                    /// 签名或粉丝
                    Container(
                      child: Row(
                        children: <Widget>[
                          Container(
                            width: px(32),
                            height: px(32),
                            margin: EdgeInsets.only(right: px(11)),
                            child: Image.asset('assets/images/icon/star.png'),
                          ),
                          Container(
                            child: Text(
                              '${item.gold}',
                              style: TextStyle(
                                fontSize: px(28),
                                color: col('fea800'),
                              ),
                            ),
                          )
                        ],
                      ),
                    )
                  ],
                ),
              ),

              /// 按钮
              Container(
                width: px(100),
                height: px(100),
                margin: EdgeInsets.only(left: px(90)),
                child: FlatButton(
                  padding: EdgeInsets.zero,
                  onPressed: () => _shiftOutClick(context, item.id),
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.all(Radius.circular(px(40)))),
                  child: Container(
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: <Widget>[
                        Container(
                          width: px(42),
                          height: px(44),
                          child: Image.asset('assets/images/icon/shiftOut.png'),
                        ),
                        Container(
                          child: Text(
                            '移出',
                            style: TextStyle(
                              fontSize: px(24),
                              color: col('303133'),
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),

        /// 分割线
        Line(
          margin: EdgeInsets.only(left: px(138)),
        )
      ],
    ));
  }
}

class BlacklistList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container();
  }
}
